package org.gc.util.comparator;

import java.util.Comparator;

import org.gc.common.vo.naturalZone.NaturalZoneVO;



public class NaturalZoneVOComparator implements Comparator<NaturalZoneVO>{
    public int compare(NaturalZoneVO arg0, NaturalZoneVO arg1) {
        int type0 = getType(arg0), type1 = getType(arg1);
        
        if(type0 > type1){
            return 1;
        }else if(type0 < type1){
            return -1;
        }else{
            return arg0.getName().compareTo(arg1.getName());
        }
        
    }
    /**
     * 获取节点的排序等级
     * @param node
     *          要检查的树节点
     * @return
     */
    private int getType(NaturalZoneVO node){
        int result = -10;
        String value = node.getName();
        
        if(value.endsWith("市")){
            result = 1;
            return result;
        }else if(value.endsWith("省")){
            result = 2;
            return result;
        }else if(value.endsWith("自治区")){
            result = 4;
            return result;
        }else if(value.endsWith("特别行政区")){
            result = 5;
            return result;
        }else if(value.endsWith("地区")){
            result = 5;
            return result;
        }else if(value.endsWith("园区")){
            result = -3;
            return result;
        }else if(value.endsWith("开发区")){
            result = -2;
            return result;
        }else if(value.endsWith("加工区")){
            result = -4;
            return result;
        }else if(value.endsWith("度假区")){
            result = -5;
            return result;
        }else if(value.endsWith("区")){
            result = -6;
            return result;
        }else if(value.endsWith("盟")){
            result = 6;
            return result;
        }else if(value.endsWith("自治县")){
            result = 9;
            return result;
        }else if(value.endsWith("县")){
            result = 8;
            return result;
        }else if(value.endsWith("街道")){
            result = 10;
            return result;
        }else if(value.endsWith("乡")){
            result = 11;
            return result;
        }else if(value.endsWith("镇")){
            result = 12;
            return result;
        }else{
            result = 20;
            return result;
        }
    }
}
